{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "6d9acdf0",
   "metadata": {},
   "source": [
    "# 元组\n",
    "\n",
    "* [元组](https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences)\n",
    "> 1. 它是和list几乎完全一样的序列数据\n",
    "> 2. 它与list不同的地方是，**不可变**（因为不可变，所以几乎没有方法）\n",
    "> 3. 元组的形式： （1，2，34，5）对比 元组（） 列表[ ]**可变**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8bad7d28",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('10001', '10002', '10003', '10001') <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "stu_id = \"10001\",\"10002\",\"10003\",\"10001\"\n",
    "# \"10001\"字符串，不能改变\n",
    "print(stu_id,type(stu_id))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8b07c60c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id.count(\"10001\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "bf6d8c73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stu_id.index(\"10002\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "80b09909",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "e61ac937",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2021, tm_mon=11, tm_mday=11, tm_hour=19, tm_min=44, tm_sec=30, tm_wday=3, tm_yday=315, tm_isdst=0)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e59144da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in module time:\n",
      "\n",
      "NAME\n",
      "    time - This module provides various functions to manipulate time values.\n",
      "\n",
      "DESCRIPTION\n",
      "    There are two standard representations of time.  One is the number\n",
      "    of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer\n",
      "    or a floating point number (to represent fractions of seconds).\n",
      "    The Epoch is system-defined; on Unix, it is generally January 1st, 1970.\n",
      "    The actual value can be retrieved by calling gmtime(0).\n",
      "    \n",
      "    The other representation is a tuple of 9 integers giving local time.\n",
      "    The tuple items are:\n",
      "      year (including century, e.g. 1998)\n",
      "      month (1-12)\n",
      "      day (1-31)\n",
      "      hours (0-23)\n",
      "      minutes (0-59)\n",
      "      seconds (0-59)\n",
      "      weekday (0-6, Monday is 0)\n",
      "      Julian day (day in the year, 1-366)\n",
      "      DST (Daylight Savings Time) flag (-1, 0 or 1)\n",
      "    If the DST flag is 0, the time is given in the regular time zone;\n",
      "    if it is 1, the time is given in the DST time zone;\n",
      "    if it is -1, mktime() should guess based on the date and time.\n",
      "\n",
      "CLASSES\n",
      "    builtins.tuple(builtins.object)\n",
      "        struct_time\n",
      "    \n",
      "    class struct_time(builtins.tuple)\n",
      "     |  struct_time(iterable=(), /)\n",
      "     |  \n",
      "     |  The time value as returned by gmtime(), localtime(), and strptime(), and\n",
      "     |  accepted by asctime(), mktime() and strftime().  May be considered as a\n",
      "     |  sequence of 9 integers.\n",
      "     |  \n",
      "     |  Note that several fields' values are not the same as those defined by\n",
      "     |  the C language standard for struct tm.  For example, the value of the\n",
      "     |  field tm_year is the actual year, not year - 1900.  See individual\n",
      "     |  fields' descriptions for details.\n",
      "     |  \n",
      "     |  Method resolution order:\n",
      "     |      struct_time\n",
      "     |      builtins.tuple\n",
      "     |      builtins.object\n",
      "     |  \n",
      "     |  Methods defined here:\n",
      "     |  \n",
      "     |  __reduce__(...)\n",
      "     |      Helper for pickle.\n",
      "     |  \n",
      "     |  __repr__(self, /)\n",
      "     |      Return repr(self).\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Static methods defined here:\n",
      "     |  \n",
      "     |  __new__(*args, **kwargs) from builtins.type\n",
      "     |      Create and return a new object.  See help(type) for accurate signature.\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data descriptors defined here:\n",
      "     |  \n",
      "     |  tm_gmtoff\n",
      "     |      offset from UTC in seconds\n",
      "     |  \n",
      "     |  tm_hour\n",
      "     |      hours, range [0, 23]\n",
      "     |  \n",
      "     |  tm_isdst\n",
      "     |      1 if summer time is in effect, 0 if not, and -1 if unknown\n",
      "     |  \n",
      "     |  tm_mday\n",
      "     |      day of month, range [1, 31]\n",
      "     |  \n",
      "     |  tm_min\n",
      "     |      minutes, range [0, 59]\n",
      "     |  \n",
      "     |  tm_mon\n",
      "     |      month of year, range [1, 12]\n",
      "     |  \n",
      "     |  tm_sec\n",
      "     |      seconds, range [0, 61])\n",
      "     |  \n",
      "     |  tm_wday\n",
      "     |      day of week, range [0, 6], Monday is 0\n",
      "     |  \n",
      "     |  tm_yday\n",
      "     |      day of year, range [1, 366]\n",
      "     |  \n",
      "     |  tm_year\n",
      "     |      year, for example, 1993\n",
      "     |  \n",
      "     |  tm_zone\n",
      "     |      abbreviation of timezone name\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Data and other attributes defined here:\n",
      "     |  \n",
      "     |  n_fields = 11\n",
      "     |  \n",
      "     |  n_sequence_fields = 9\n",
      "     |  \n",
      "     |  n_unnamed_fields = 0\n",
      "     |  \n",
      "     |  ----------------------------------------------------------------------\n",
      "     |  Methods inherited from builtins.tuple:\n",
      "     |  \n",
      "     |  __add__(self, value, /)\n",
      "     |      Return self+value.\n",
      "     |  \n",
      "     |  __contains__(self, key, /)\n",
      "     |      Return key in self.\n",
      "     |  \n",
      "     |  __eq__(self, value, /)\n",
      "     |      Return self==value.\n",
      "     |  \n",
      "     |  __ge__(self, value, /)\n",
      "     |      Return self>=value.\n",
      "     |  \n",
      "     |  __getattribute__(self, name, /)\n",
      "     |      Return getattr(self, name).\n",
      "     |  \n",
      "     |  __getitem__(self, key, /)\n",
      "     |      Return self[key].\n",
      "     |  \n",
      "     |  __getnewargs__(self, /)\n",
      "     |  \n",
      "     |  __gt__(self, value, /)\n",
      "     |      Return self>value.\n",
      "     |  \n",
      "     |  __hash__(self, /)\n",
      "     |      Return hash(self).\n",
      "     |  \n",
      "     |  __iter__(self, /)\n",
      "     |      Implement iter(self).\n",
      "     |  \n",
      "     |  __le__(self, value, /)\n",
      "     |      Return self<=value.\n",
      "     |  \n",
      "     |  __len__(self, /)\n",
      "     |      Return len(self).\n",
      "     |  \n",
      "     |  __lt__(self, value, /)\n",
      "     |      Return self<value.\n",
      "     |  \n",
      "     |  __mul__(self, value, /)\n",
      "     |      Return self*value.\n",
      "     |  \n",
      "     |  __ne__(self, value, /)\n",
      "     |      Return self!=value.\n",
      "     |  \n",
      "     |  __rmul__(self, value, /)\n",
      "     |      Return value*self.\n",
      "     |  \n",
      "     |  count(self, value, /)\n",
      "     |      Return number of occurrences of value.\n",
      "     |  \n",
      "     |  index(self, value, start=0, stop=9223372036854775807, /)\n",
      "     |      Return first index of value.\n",
      "     |      \n",
      "     |      Raises ValueError if the value is not present.\n",
      "\n",
      "FUNCTIONS\n",
      "    asctime(...)\n",
      "        asctime([tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string, e.g. 'Sat Jun 06 16:26:11 1998'.\n",
      "        When the time tuple is not present, current time as returned by localtime()\n",
      "        is used.\n",
      "    \n",
      "    ctime(...)\n",
      "        ctime(seconds) -> string\n",
      "        \n",
      "        Convert a time in seconds since the Epoch to a string in local time.\n",
      "        This is equivalent to asctime(localtime(seconds)). When the time tuple is\n",
      "        not present, current time as returned by localtime() is used.\n",
      "    \n",
      "    get_clock_info(...)\n",
      "        get_clock_info(name: str) -> dict\n",
      "        \n",
      "        Get information of the specified clock.\n",
      "    \n",
      "    gmtime(...)\n",
      "        gmtime([seconds]) -> (tm_year, tm_mon, tm_mday, tm_hour, tm_min,\n",
      "                               tm_sec, tm_wday, tm_yday, tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing UTC (a.k.a.\n",
      "        GMT).  When 'seconds' is not passed in, convert the current time instead.\n",
      "        \n",
      "        If the platform supports the tm_gmtoff and tm_zone, they are available as\n",
      "        attributes only.\n",
      "    \n",
      "    localtime(...)\n",
      "        localtime([seconds]) -> (tm_year,tm_mon,tm_mday,tm_hour,tm_min,\n",
      "                                  tm_sec,tm_wday,tm_yday,tm_isdst)\n",
      "        \n",
      "        Convert seconds since the Epoch to a time tuple expressing local time.\n",
      "        When 'seconds' is not passed in, convert the current time instead.\n",
      "    \n",
      "    mktime(...)\n",
      "        mktime(tuple) -> floating point number\n",
      "        \n",
      "        Convert a time tuple in local time to seconds since the Epoch.\n",
      "        Note that mktime(gmtime(0)) will not generally return zero for most\n",
      "        time zones; instead the returned value will either be equal to that\n",
      "        of the timezone or altzone attributes on the time module.\n",
      "    \n",
      "    monotonic(...)\n",
      "        monotonic() -> float\n",
      "        \n",
      "        Monotonic clock, cannot go backward.\n",
      "    \n",
      "    monotonic_ns(...)\n",
      "        monotonic_ns() -> int\n",
      "        \n",
      "        Monotonic clock, cannot go backward, as nanoseconds.\n",
      "    \n",
      "    perf_counter(...)\n",
      "        perf_counter() -> float\n",
      "        \n",
      "        Performance counter for benchmarking.\n",
      "    \n",
      "    perf_counter_ns(...)\n",
      "        perf_counter_ns() -> int\n",
      "        \n",
      "        Performance counter for benchmarking as nanoseconds.\n",
      "    \n",
      "    process_time(...)\n",
      "        process_time() -> float\n",
      "        \n",
      "        Process time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    process_time_ns(...)\n",
      "        process_time() -> int\n",
      "        \n",
      "        Process time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    sleep(...)\n",
      "        sleep(seconds)\n",
      "        \n",
      "        Delay execution for a given number of seconds.  The argument may be\n",
      "        a floating point number for subsecond precision.\n",
      "    \n",
      "    strftime(...)\n",
      "        strftime(format[, tuple]) -> string\n",
      "        \n",
      "        Convert a time tuple to a string according to a format specification.\n",
      "        See the library reference manual for formatting codes. When the time tuple\n",
      "        is not present, current time as returned by localtime() is used.\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    strptime(...)\n",
      "        strptime(string, format) -> struct_time\n",
      "        \n",
      "        Parse a string to a time tuple according to a format specification.\n",
      "        See the library reference manual for formatting codes (same as\n",
      "        strftime()).\n",
      "        \n",
      "        Commonly used format codes:\n",
      "        \n",
      "        %Y  Year with century as a decimal number.\n",
      "        %m  Month as a decimal number [01,12].\n",
      "        %d  Day of the month as a decimal number [01,31].\n",
      "        %H  Hour (24-hour clock) as a decimal number [00,23].\n",
      "        %M  Minute as a decimal number [00,59].\n",
      "        %S  Second as a decimal number [00,61].\n",
      "        %z  Time zone offset from UTC.\n",
      "        %a  Locale's abbreviated weekday name.\n",
      "        %A  Locale's full weekday name.\n",
      "        %b  Locale's abbreviated month name.\n",
      "        %B  Locale's full month name.\n",
      "        %c  Locale's appropriate date and time representation.\n",
      "        %I  Hour (12-hour clock) as a decimal number [01,12].\n",
      "        %p  Locale's equivalent of either AM or PM.\n",
      "        \n",
      "        Other codes may be available on your platform.  See documentation for\n",
      "        the C library strftime function.\n",
      "    \n",
      "    thread_time(...)\n",
      "        thread_time() -> float\n",
      "        \n",
      "        Thread time for profiling: sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    thread_time_ns(...)\n",
      "        thread_time() -> int\n",
      "        \n",
      "        Thread time for profiling as nanoseconds:\n",
      "        sum of the kernel and user-space CPU time.\n",
      "    \n",
      "    time(...)\n",
      "        time() -> floating point number\n",
      "        \n",
      "        Return the current time in seconds since the Epoch.\n",
      "        Fractions of a second may be present if the system clock provides them.\n",
      "    \n",
      "    time_ns(...)\n",
      "        time_ns() -> int\n",
      "        \n",
      "        Return the current time in nanoseconds since the Epoch.\n",
      "\n",
      "DATA\n",
      "    altzone = -32400\n",
      "    daylight = 0\n",
      "    timezone = -28800\n",
      "    tzname = ('中国标准时间', '中国夏令时')\n",
      "\n",
      "FILE\n",
      "    (built-in)\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(time)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d9cf2bdf",
   "metadata": {},
   "source": [
    "# 字典\n",
    "* 数据形式{'keys':value,'xx':xx}\n",
    "* keys 可用字符串或数值定义，具有一定意义的索引值\n",
    "* tuples 不可变类型数值\n",
    "* list有append()  extend()方法改变\n",
    "\n",
    "> 1.创建字典的三种常见方法\n",
    ">> 1. 直接按照字典的格式创建 ： {key1:value1 ,key2:value2 ,....}\n",
    ">> 2. dict()函数来创建字典：dict(key1=value2,key2=value2,...)\n",
    ">> 3. 字典数据增加的方式：新建空字典 dict_name{} ,dict_name[key1]=value1 ... \n",
    "> 2. 字典的性质\n",
    "\n",
    "* key 唯一性、不可变性\n",
    "* dict 是无序的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8119680f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_10001': 'Alex', 'stud_10002': 'Jack', 'stud_10003': 'Marry'}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1. 直接按照字典的格式创建 ： {key1:value1 ,key2:value2 ,....}\n",
    "stud_info = {\n",
    "    \"stud_10001\":\"Alex\",   #,， ：； 【】[]  () （）\n",
    "    \"stud_10002\":\"Jack\",\n",
    "    \"stud_10003\":\"Marry\"\n",
    "}\n",
    "stud_info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8cc1c386",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_10001': 'Alex', 'stud_10002': 'Jack', 'stud_10003': 'Marry'}"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2. dict()函数来创建字典：dict(key1=value2,key2=value2,...)\n",
    "stu_info_02 = dict(\n",
    "    stud_10001 = \"Alex\",\n",
    "    stud_10002 = \"Jack\",\n",
    "    stud_10003 = \"Marry\"\n",
    ")\n",
    "stu_info_02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "643225f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "stud_info_03 = {}\n",
    "stud_info_03[\"stud_10001\"] = \"Alex\"\n",
    "stud_info_03[\"stud_10002\"] = \"Jack\"\n",
    "stud_info_03[\"stud_10003\"] = \"Marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "01ce8e67",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'stud_10001': 'Alex', 'stud_10002': 'Jack', 'stud_10003': 'Marry'}"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info_03"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "30ce461d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_keys(['stud_10001', 'stud_10002', 'stud_10003'])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info_03.keys()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "07090bc7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dict_values(['Alex', 'Jack', 'Marry'])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stud_info_03.values()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fca608f6",
   "metadata": {},
   "source": [
    "### 课后代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "109d7c81",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Karry', 'stu1802': 'Roy', 'stu1803': 'Jackson'}\n"
     ]
    }
   ],
   "source": [
    "info = {\n",
    "    \"stu1801\":\"Karry\",\n",
    "    \"stu1802\":\"Roy\",\n",
    "    \"stu1803\":\"Jackson\"\n",
    "}\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "89b47ea4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Karry', 'stu1802': 'Roy', 'stu1803': 'Jackson', 'stu1804': 'Haixin'}\n"
     ]
    }
   ],
   "source": [
    "#  增加变量\n",
    "info[\"stu1804\"] = \"Haty\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "78b9fda0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Karry', 'stu1802': 'Roy', 'stu1803': 'Jackson', 'stu1804': 'Haixin'}\n"
     ]
    }
   ],
   "source": [
    "# 修改已输入的变量\n",
    "info[\"stu1804\"] = \"Haixin\"\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8727c43a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Karry', 'stu1802': 'Roy', 'stu1803': 'Jackson'}\n"
     ]
    }
   ],
   "source": [
    "# 删除变量的方法\n",
    "# 1. 标准删除姿势\n",
    "info.pop(\"stu1804\")\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "19529b96",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1802': 'Roy', 'stu1803': 'Jackson'}\n"
     ]
    }
   ],
   "source": [
    "# 2. 使用del删除，内容可回顾list\n",
    "del info[\"stu1801\"] \n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "926a6b8a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu1801': 'Karry', 'stu1802': 'Roy'}\n"
     ]
    }
   ],
   "source": [
    "# 3. popitem 随机删除\n",
    "\n",
    "info = {\"stu1801\":\"Karry\",\"stu1802\":\"Roy\",\"stu1803\":\"Jackson\"}\n",
    "info.popitem()\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1054b262",
   "metadata": {},
   "source": [
    "### 课本练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "0675ffe1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Provide a word to search for vowels:water\n",
      "dict_items([('a', 1), ('e', 1), ('i', 0), ('o', 0), ('u', 0)])\n",
      "a was found 1 time(s)\n",
      "e was found 1 time(s)\n",
      "i was found 0 time(s)\n",
      "o was found 0 time(s)\n",
      "u was found 0 time(s)\n",
      "{'a': 1, 'e': 1, 'i': 0, 'o': 0, 'u': 0}\n"
     ]
    }
   ],
   "source": [
    "# 频度计数\n",
    "\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = input(\"Provide a word to search for vowels:\")\n",
    "found = {}\n",
    "\n",
    "found[\"a\"]=0        #将元音计数初始化为0\n",
    "found[\"e\"]=0\n",
    "found[\"i\"]=0\n",
    "found[\"o\"]=0\n",
    "found[\"u\"]=0\n",
    "\n",
    "found = found.fromkeys(vowels,0)\n",
    " \n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        found[letter] += 1  # += 操作符中的letter与元音相关联，递增计数的值\n",
    "print(found.items())        \n",
    "\n",
    "for k,v in found.items():        #  items方法传回两个循环变量\n",
    "    print(k,\"was found\",v,\"time(s)\")\n",
    "print(found)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
